<?php
	include("includes/session.php"); 
	include("includes/connect_db.php");
	include("includes/header.php"); 
	include("notif.php");
?>

<STYLE TYPE="text/css">
	.autostart{
		width: 100%;
		position: center;
		text-align: center;
		margin-top: 100px;
	}
	.service{
		width: 100%;
		position: center;
		text-align: center;
		margin-top: 10px;
	}
	.autostart .btn{
		margin: auto;
		width: 250px;
		padding: 10px;
		border-radius: 10px;
	}
	.judul{
		text-align: center;
		padding-top: 200px;
		padding-bottom: 10px;
	}
	.service .btn{
		width: 100px;
		border-radius: 5px;
	}
	.border{
		position: center;
		width: 200px;
		margin-left: auto;
		margin-right: auto;
		padding: 5px;
		margin-top: 10px;
	}
</STYLE>

<div class="span9"> 
	<div class="span12 judul" style="text-align: center;">
		<h2>Aktivasi Fitur AutoStart</h2>
	</div>

	<div id="placer">
		<?php
			$sql = "SELECT * FROM tb_autostart";
			$query = mysql_query($sql);
			$hasil = mysql_fetch_array($query);

			if ($hasil['autostart'] == "1") {
				
		?>
				<div class='autostart'>
					<button class='status btn btn-success tidakAktif'>
						<i class='icon-white icon-off icon-large'></i>
						Autostart Service On
					</button>
				</div>
		<?php
			} else {
		?>
				<div class="autostart">
					<button class="status btn btn-danger aktif">
						<i class="icon-white icon-off icon-large"></i>
						Autostart Service Off
					</button>
				</div>
				<div class="border">
					<?php
						passthru("net start > service.log");
						$handle = fopen("service.log", "r");
						while (!feof($handle))
						{
						   $baristeks = fgets($handle);
						   if (substr_count($baristeks, 'Gammu SMSD Service (GammuSMSD)') > 0)
						   {
						     $status = 1;
						   }
						}
						fclose($handle);
						if ($status == 1) {
					?>
							<div class="service">
								Status Service
								<button class="status btn btn-success mati">
									<i class="icon-white icon-off"></i>
									On
								</button>
							</div>
					<?php
						} else if ($status == 0) {
					?>
							<div class="service">
								Status Service
								<button class="status btn btn-danger hidup">
									<i class="icon-white icon-off"></i>
									Off
								</button>
							</div>
					<?php
						}
					?>
				</div>
		<?php
			}
		?>
	</div>
</div>

<SCRIPT TYPE="text/javascript">
	$(document).ready(function() {
		$('.tidakAktif').live('click', function(){
			$.ajax({
			  url: 'act_service.php?aksi=1',
			  type: 'POST',
			  success: function(data, textStatus, xhr) {
				$("#placer").html(
					"<div class='autostart'>"+
						"<button class='status btn btn-danger aktif'>"+
							"<i class='icon-white icon-off icon-large'></i>"+
							" Autostart Service Off"+
						"</button>"+
					"</div>"
				);

				$.ajax({
				    url: 'act_service.php?aksi=3',
				    type: 'POST',
				    success: function(data, textStatus, xhr) {
				      $('#placer').append(data);
				    }
				});
			  }
			});
			return false;
		});

		$('.aktif').live('click', function(){
			$.ajax({
			  url: 'act_service.php?aksi=2',
			  type: 'POST',
			  success: function(data, textStatus, xhr) {
				$("#placer").html(
					"<div class='autostart'>"+
						"<button class='status btn btn-success tidakAktif'>"+
							"<i class='icon-white icon-off icon-large'></i>"+
							" Autostart Service On"+
						"</button>"+
					"</div>"
				);
			  }
			});
			return false;
		});

		$('.mati').live('click', function(){
			$.ajax({
			  url: 'act_service.php?aksi=4',
			  type: 'POST',
			  success: function(data, textStatus, xhr) {
				$(".service").html(
					"Status Service "+
					"<button class='status btn btn-danger hidup'>"+
						"<i class='icon-white icon-off'></i>"+
						" Off"+
					"</button>");
			  }
			});
			return false;
		});

		$('.hidup').live('click', function(){
			$.ajax({
			  url: 'act_service.php?aksi=5',
			  type: 'POST',
			  success: function(data, textStatus, xhr) {
				// window.location = 'service.php';
				$(".service").html(
					"Status Service "+
					"<button class='status btn btn-success mati'>"+
						"<i class='icon-white icon-off'></i>"+
						" On"+
					"</button>");
			  }
			});
			return false;
		});
	});
</SCRIPT>

<?php include("includes/footer.php"); ?>
